package com.itheima.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.server.domain.Course;
import com.itheima.server.dto.CourseQueryDto;
import com.itheima.server.service.CourseService;
import com.itheima.server.mapper.CourseMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
* @author li
* @description 针对表【hk_course(课程表)】的数据库操作Service实现
* @createDate 2025-09-04 20:47:39
*/
@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {

    @Override
    public List<Course> pageQuery(CourseQueryDto dto) {
        Page<Course> page = new Page<>(dto.getPageNum(), dto.getPageSize());
        String code = dto.getCode();
        String name = dto.getName();
        String subject = dto.getSubject();
        String applicablePerson = dto.getApplicablePerson();
        String beginCreateTime = dto.getParams().get("beginCreateTime");
        String endCreateTime = dto.getParams().get("endCreateTime");
        LambdaQueryWrapper<Course> wrapper = new LambdaQueryWrapper<Course>()
                .like(StringUtils.hasText(code), Course::getCode, code)
                .like(StringUtils.hasText(name), Course::getName, name)
                .like(StringUtils.hasText(subject), Course::getSubject, subject)
                .like(StringUtils.hasText(applicablePerson), Course::getApplicablePerson, applicablePerson);
        if (StringUtils.hasText(beginCreateTime) && StringUtils.hasText(endCreateTime)){
            wrapper.between(Course::getCreateTime, beginCreateTime, endCreateTime);
        }
        super.page(page,wrapper);

        return page.getRecords();
    }
}




